<?php

namespace yak\layui\widgets\search;

use yii\base\Widget;
use yii\helpers\Html;

class DropDownSearch extends Widget
{
    /**
     * @var string
     */
    public $selectName = 'yak_lst';

    /**
     * @var string
     */
    public $inputName = 'yak_lst_txt';

    /**
     * @var \yii\base\Model
     */
    public $model;

    /**
     * @var array
     */
    public $items = [];

    /**
     * @var array
     */
    public $inputOption = ['size' => 35];

    /**
     * @var string
     */
    public $selectExtName = 'yak_lst_ext';

    /**
     * @var string
     */
    public $selectExt = 'compare';

    public function run()
    {
        $list = [];

        foreach ($this->items as $key => $item) {
            $list[$item] = $this->model->getAttributeLabel($item);
        }

        $selectName = $this->selectName;
        $selection = Html::dropDownList($selectName, null, $list, ['size' => '16']);

        $this->inputOption['class'] = 'layui-input';

        $inputName = $this->inputName;
        $value = empty($params[$this->inputName]) ? '' : $params[$this->inputName];

        $input = Html::input('text', $inputName, $value, $this->inputOption);

        $ext = '';
        if (!empty($this->selectExt)) {

            switch ($this->selectExt) {
                default:
                    $_list = ['EQ' => '精确', 'LIKE' => '模糊'];
            }

            $ext = Html::dropDownList($this->selectExtName, empty($params[$this->selectExtName]) ? '' : $params[$this->selectExtName], $_list, []);
        }

        return "<div class='layui-inline layui-inline-group-item'>{$selection}</div>\n<div class='layui-inline layui-inline-group-item'>{$input}</div>\n<div class='layui-inline layui-inline-group-item'>{$ext}</div>";
    }
}